package com.olocat.cjx.nsims.service.impl

import com.olocat.cjx.nsims.dao.NoticeRepository
import com.olocat.cjx.nsims.pojo.notice.Notice
import com.olocat.cjx.nsims.service.NoticeService
import org.springframework.stereotype.Service
import javax.annotation.Resource

@Service
class NoticeServiceImpl : NoticeService {
    @Resource
    lateinit var noticeRepository: NoticeRepository

    override fun save(notice: Notice) {
        noticeRepository.save(notice)
    }

    override fun getNoticeByUserId(userId: String): List<Notice> {
        return noticeRepository.getNoticesByUserId(userId)
    }

    override fun countNotices(userId: String): Int {
        return noticeRepository.countNoticesByUserIdAndStateEquals(userId, false)
    }

    override fun readAll(id: String) {
        noticeRepository.updateStateById(id, true)
    }
}